package com.telit.common.util;

import com.telit.common.entity.*;
import com.telit.common.service.BaiduService;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.util.List;


@Component
public class BaiduUtils {

    private static BaiduService baiduService;

    public BaiduUtils(BaiduService baiduService) {
        BaiduUtils.baiduService = baiduService;
    }

    /**
     * 驾车
     *
     * @param origin
     * @param destination
     * @param coord_type
     *
     * @return
     */
    public static BaiduMapInfo<Result> driving(String origin, String destination, String coord_type) {
        return baiduService.driving(origin, destination, coord_type);
    }

    /**
     * 骑行
     *
     * @param origin
     * @param destination
     * @param coord_type
     *
     * @return
     */
    public static BaiduMapInfo<Result> riding(String origin, String destination, String coord_type) {
        return baiduService.riding(origin, destination, coord_type);
    }

    /**
     * 步行
     *
     * @param origin
     * @param destination
     * @param coord_type
     *
     * @return
     */
    public static BaiduMapInfo<Result> walking(String origin, String destination, String coord_type) {
        return baiduService.walking(origin, destination, coord_type);
    }

    /**
     * 地址查询
     *
     * @param query  关键字
     * @param region 城市
     * @param county 区县
     *
     * @return
     */
    public static BaiduMapInfo<List<AddressResult>> promptAddress(String query, String province, String region,
                                                                  String county, String coordType, boolean cityLimit)
            throws UnsupportedEncodingException {
        return baiduService.promptAddress(query, province, region, county, coordType, cityLimit);
    }

    /**
     * poi检索
     *
     * @param query
     * @param region
     * @param coordType
     *
     * @return
     * @throws UnsupportedEncodingException
     */
    public static POIMapInfo searchAddress(String query, String region, String coordType)
            throws UnsupportedEncodingException {
        return baiduService.poiMapInfo(query, region, coordType);
    }

    /**
     * 地点详细信息
     *
     * @param uid
     *
     * @return
     */
    public static BaiduMapInfo<DetailAddressResult> getDetailAddress(String uid) {
        return baiduService.getDetailAddress(uid);
    }

    /**
     * 根据经纬度查询详细地点
     */
    public static String queryAddressByLaAndLo(String longitude, String latitude) {
        return baiduService.queryAddressByLaAndLo(longitude, latitude);
    }

}
